﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Gma.QrCodeNet.Encoding;

namespace QRCodeUI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = textBox1.Lines[0];
            Graphics g = Graphics.FromHwnd(Handle);
            Font f = new Font("宋体", 20);
            Brush b;
            b = new SolidBrush(Color.Black);
            string sampleText = s;
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
            QrCode qrCode = qrEncoder.Encode(sampleText);
            string [] s1 = new String[qrCode.Matrix.Width];
            for (int j = 0; j < qrCode.Matrix.Width; j++)
            {
                for (int i = 0; i < qrCode.Matrix.Width; i++)
                {

                    char charToPrint = qrCode.Matrix[i, j] ? '█' : '　';
                    s1[j]=s1[j] + charToPrint;
                }
                
            }
            int v = 50;
            for (int i = 0; i < qrCode.Matrix.Width; i++)
            {
                g.DrawString(s1[i], f, b, 50, v);
                v += 20;
            }
            g.Dispose();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
